package com.fake_Interviews.controller;

public class MyResponse<T> {
    private final String status;
    private final String message;
    private final T data;

    /**
     * 成功的响应，把数据放入 data 里
     * 示例：
     * {
     *     "status": "OK",
     *     "message": null,
     *     "data": {
     *         ...
     *     }
     * }
     */
    public static <K> MyResponse<K> ok(K k){
        return new MyResponse<>("OK", null, k);
    }

    /**
     * 失败的响应，错误信息放入 message 里
     * 示例：
     * {
     *     "status": "ERROR",
     *     "message": "...",
     *     "data": null
     * }
     */
    public static <K> MyResponse<K> error(String message){
        return new MyResponse<>("ERROR", message, null);
    }

    private MyResponse(String status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public String getStatus() {
        return status;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }
}
